//
//  ChanpinxiangqingViewController.m
//  tianjin
//
//  Created by 鞠超 on 16/8/8.
//  Copyright © 2016年 jc. All rights reserved.
//

#import "ChanpinxiangqingViewController.h"

#import "VOTagList.h"
#import "PinglunliebiaoViewController.h"
#import "QugouwuchejiesuanViewController.h"

@interface ChanpinxiangqingViewController () <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UIImageView * image_return;
@property (nonatomic, strong) UIButton * btn_return;

//
@property (nonatomic, strong) UITableView * tableView;

//轮播图
@property (nonatomic, strong) UIScrollView * lunbo_scrollView;
@property (nonatomic, strong) UIPageControl * lunbo_pageControl;
@property (nonatomic, strong) NSTimer * lunbo_timer;
@property (nonatomic, assign) BOOL isplay;
//轮播展示图片
@property (nonatomic, strong) UIImageView * image1;
@property (nonatomic, strong) UIImageView * image2;
//显示
@property (nonatomic, strong) UILabel * name_product;
@property (nonatomic, strong) UILabel * price_product;
@property (nonatomic, strong) UILabel * oldPrice_product;
@property (nonatomic, strong) UILabel * yishou_product;

//规格
@property (nonatomic, strong) VOTagList * tagList;
//评价
@property (nonatomic, strong) UILabel * pingjia_product;
//
@property (nonatomic, strong) UIImageView * image_touxiang;
@property (nonatomic, strong) UILabel * name_user;
@property (nonatomic, strong) UILabel * time_pinglun;
@property (nonatomic, strong) UILabel * pinglun_detail;

//web
@property (nonatomic, strong) UIWebView * webView;


//请求数据
@property (nonatomic, strong) NSMutableArray * arr_lunboData;
@property (nonatomic, strong) NSMutableArray * arr_listData;

@end

@implementation ChanpinxiangqingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self p_navi];
    
    [self p_setupView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - navi
- (void )p_navi
{
    _btnLeft.hidden = YES;
    _lblLeft.hidden = YES;
    _lblTitle.hidden = YES;
    _btnRight.hidden = YES;
    _lblRight.hidden = YES;
    _topView.hidden = YES;
    
    UIView * view_bg = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 20)];
    view_bg.backgroundColor = [UIColor blackColor];
    [self.view addSubview:view_bg];
    
    self.image_return = [[UIImageView alloc] initWithFrame:CGRectMake(10, 20 + 10, 25, 25)];
    self.image_return.image = [UIImage imageNamed:@"zuofanhui1@2x.png"];
    self.image_return.userInteractionEnabled = YES;
    [self.view addSubview:self.image_return];
    
    self.btn_return = [UIButton buttonWithType:(UIButtonTypeSystem)];
    self.btn_return.frame = CGRectMake(5, 20 + 5, 35, 35);
    [self.view addSubview:self.btn_return];
    [self.btn_return addTarget:self action:@selector(btn_returnAction:) forControlEvents:(UIControlEventTouchUpInside)];
}

//左返回
- (void )btn_returnAction:(UIButton *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

//显示tabbar
- (void )viewWillAppear:(BOOL)animated
{
    [(AppDelegate *)[[UIApplication sharedApplication] delegate] hiddenTabBar];
}

#pragma mark - 布局
- (void )p_setupView
{
    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
    //底部栏
    [self p_bottomView];
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 20, SCREEN_WIDTH, SCREEN_HEIGHT - 20 - 50) style:(UITableViewStylePlain)];
    self.tableView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self p_webView];
    self.tableView.tableFooterView = self.webView;
    
    [self.view addSubview:self.tableView];
    
    [self.view bringSubviewToFront:self.image_return];
    [self.view bringSubviewToFront:self.btn_return];
}

#pragma mark - tableview代理
- (NSInteger )numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 5;
}

- (CGFloat )tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.row == 0)
    {
        return SCREEN_WIDTH;
    }
    else if(indexPath.row == 1)
    {
        return 69;
    }
    else if(indexPath.row == 2)
    {
        return 60;
    }
    else if(indexPath.row == 3)
    {
        return 50;
    }
    else if(indexPath.row == 4)
    {
        CGFloat length_W = [@"很好的,比较好,可以谁看见的开始就打开手机端快捷斯柯达就数据库的紧身裤角度看" boundingRectWithSize:CGSizeMake(SCREEN_WIDTH - 20, 10000)    options:(NSStringDrawingUsesLineFragmentOrigin) attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:14]} context:nil].size.height;

        return 50 + length_W + 20 + 40;
        
//        return 40;
    }
    else
    {
        return 150;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * cell = [[UITableViewCell alloc] init];
    
    if(indexPath.row == 0)
    {
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self p_lunbotu];
        
        [cell addSubview:self.lunbo_scrollView];
        [cell addSubview:self.lunbo_pageControl];
    }
    else if(indexPath.row == 1)
    {
        cell.selectionStyle = UITableViewCellSelectionStyleNone;

        self.name_product = [[UILabel alloc] initWithFrame:CGRectMake(10, 15, SCREEN_WIDTH - 20, 20)];
        self.name_product.text = @"浙江甜橙(肉粒饱满,水分充足)";
        self.name_product.textColor = [UIColor blackColor];
        self.name_product.font = [UIFont systemFontOfSize:17];
        [cell addSubview:self.name_product];
        
        //获得长度
        CGFloat length_W = [@"￥999.9" boundingRectWithSize:CGSizeMake(200, 20)    options:(NSStringDrawingUsesLineFragmentOrigin) attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:16]} context:nil].size.width;
        
        self.price_product = [[UILabel alloc] initWithFrame:CGRectMake(10, CGRectGetMaxY(self.name_product.frame) + 5, length_W, 20)];
        self.price_product.text = @"￥999.9";
        self.price_product.textColor = [UIColor redColor];
        self.price_product.font = [UIFont systemFontOfSize:16];
        [cell addSubview:self.price_product];
        
        
        CGFloat length_W1 = [@"￥1099.9" boundingRectWithSize:CGSizeMake(200, 20)    options:(NSStringDrawingUsesLineFragmentOrigin) attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:13]} context:nil].size.width;
        //
        self.oldPrice_product = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.price_product.frame) + 3, CGRectGetMinY(self.price_product.frame) + 5, length_W1, 15)];
        self.oldPrice_product.textColor = [UIColor grayColor];
        self.oldPrice_product.text = @"￥1099.9";
        self.oldPrice_product.font = [UIFont systemFontOfSize:13];
        [cell addSubview:self.oldPrice_product];
        
        UIView * view_line = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetMinX(self.oldPrice_product.frame) + 3, CGRectGetMidY(self.oldPrice_product.frame), length_W1, 1)];
        view_line.backgroundColor = [UIColor grayColor];
        [cell addSubview:view_line];
        
        //
        self.yishou_product = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 10 - 100, CGRectGetMinY(self.price_product.frame) + 3, 100, 15)];
        self.yishou_product.text = @"已售12999";
        self.yishou_product.textColor = [UIColor grayColor];
        self.yishou_product.textAlignment = NSTextAlignmentRight;
        self.yishou_product.font = [UIFont systemFontOfSize:14];
        [cell addSubview:self.yishou_product];
        
        UIView * view_line1 = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.oldPrice_product.frame) + 8, SCREEN_WIDTH, 1)];
        view_line1.backgroundColor = [UIColor groupTableViewBackgroundColor];
        [cell addSubview:view_line1];
    }
    else if(indexPath.row == 2)
    {
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        //标签内容
        self.tagList = [[VOTagList alloc] initWithTags:@[@"1个",@"5个",@"10个",@"50个"]];
        
        self.tagList.frame = CGRectMake(20, 10, SCREEN_WIDTH - 40, 35);
        self.tagList.multiLine = YES;
        self.tagList.multiSelect = NO;
        self.tagList.allowNoSelection = YES;
        self.tagList.vertSpacing = 10;
        self.tagList.horiSpacing = 15;
        self.tagList.tagBackgroundColor = [UIColor groupTableViewBackgroundColor];
        self.tagList.selectedTagBackgroundColor = navi_bar_bg_color;
        self.tagList.selectedTextColor = [UIColor whiteColor];
        self.tagList.textColor = [UIColor grayColor];
        self.tagList.tagCornerRadius = 2;
        self.tagList.tagEdge = UIEdgeInsetsMake(6, 6, 6, 6);
        [self.tagList addTarget:self action:@selector(selectedTagsChanged:) forControlEvents:UIControlEventValueChanged];
        [cell addSubview:self.tagList];
        //
        UIView * view_line = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.tagList.frame) + 5, SCREEN_WIDTH, 10)];
        view_line.backgroundColor = [UIColor groupTableViewBackgroundColor];
        [cell addSubview:view_line];
    }
    else if(indexPath.row == 3)
    {
        cell.selectionStyle = UITableViewCellSelectionStyleNone;

        self.pingjia_product = [[UILabel alloc] initWithFrame:CGRectMake(10, 15, 200, 20)];
        self.pingjia_product.textColor = [UIColor blackColor];
        self.pingjia_product.text = @"评价(1099)";
        self.pingjia_product.font = [UIFont systemFontOfSize:16];
        
        [cell addSubview:self.pingjia_product];
        
        UILabel * Gengduo = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 10 - 100, 15, 100, 20)];
        Gengduo.text = @"查看更多>";
        Gengduo.font = [UIFont systemFontOfSize:14];
        Gengduo.textColor = [UIColor grayColor];
        Gengduo.textAlignment = NSTextAlignmentRight;
        [cell addSubview:Gengduo];
        
        UIView * view_line = [[UIView alloc] initWithFrame:CGRectMake(0, 49, SCREEN_WIDTH, 1)];
        view_line.backgroundColor = [UIColor groupTableViewBackgroundColor];
        [cell addSubview:view_line];
    }
    else if(indexPath.row == 4)
    {
        cell.selectionStyle = UITableViewCellSelectionStyleNone;

        self.image_touxiang = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 40, 40)];
        self.image_touxiang.image = [UIImage imageNamed:@"chanpingPic@2x.png"];
        self.image_touxiang.layer.cornerRadius = 20;
        self.image_touxiang.layer.masksToBounds = YES;
        [cell addSubview:self.image_touxiang];
        
        self.name_user = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.image_touxiang.frame) + 10, 12, SCREEN_WIDTH - CGRectGetMaxX(self.image_touxiang.frame) - 20, 15)];
        self.name_user.text = @"用户昵称";
        self.name_user.font = [UIFont systemFontOfSize:14];
        [cell addSubview:self.name_user];
        
        self.time_pinglun = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.image_touxiang.frame) + 10, CGRectGetMaxY(self.name_user.frame) + 8, SCREEN_WIDTH - CGRectGetMaxX(self.image_touxiang.frame) - 20, 15)];
        self.time_pinglun.text = @"2016-8-20";
        self.time_pinglun.font = [UIFont systemFontOfSize:14];
        self.time_pinglun.textColor = [UIColor grayColor];
        [cell addSubview:self.time_pinglun];
        
        CGFloat length_W = [@"很好的,比较好,可以谁看见的开始就打开手机端快捷斯柯达就数据库的紧身裤角度看" boundingRectWithSize:CGSizeMake(SCREEN_WIDTH - 20, 10000)    options:(NSStringDrawingUsesLineFragmentOrigin) attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:14]} context:nil].size.height;
        
        self.pingjia_product = [[UILabel alloc] initWithFrame:CGRectMake(10, CGRectGetMaxY(self.image_touxiang.frame) + 10, SCREEN_WIDTH - 20, length_W)];
        self.pingjia_product.text = @"很好的,比较好,可以谁看见的开始就打开手机端快捷斯柯达就数据库的紧身裤角度看";
        self.pingjia_product.numberOfLines = 0;
        self.pingjia_product.font = [UIFont systemFontOfSize:14];
        [cell addSubview:self.pingjia_product];
        
        UIImageView * image_xiangqing = [[UIImageView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.pingjia_product.frame) + 10, SCREEN_WIDTH, 40)];
        image_xiangqing.image = [UIImage imageNamed:@"XQ-6@2x.png"];
        [cell addSubview:image_xiangqing];
        
        UILabel * xiangqing = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH / 2 - 50, 10, 100, 20)];
        xiangqing.text = @"查看详情";
        xiangqing.textAlignment = NSTextAlignmentCenter;
        xiangqing.font = [UIFont systemFontOfSize:16];
        [image_xiangqing addSubview:xiangqing];
        
//        UIImageView * image_xiangqing = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 40)];
//        image_xiangqing.image = [UIImage imageNamed:@"XQ-6@2x.png"];
//        [cell addSubview:image_xiangqing];
//        
//        UILabel * xiangqing = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH / 2 - 50, 10, 100, 20)];
//        xiangqing.text = @"查看详情";
//        xiangqing.textAlignment = NSTextAlignmentCenter;
//        xiangqing.font = [UIFont systemFontOfSize:16];
//        [image_xiangqing addSubview:xiangqing];
    }
    
    return cell;
}

- (void )tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if(indexPath.row == 3)
    {
//        NSLog(@"跳转到评论详情页面");
        
        PinglunliebiaoViewController * pinglunliebiaoViewController = [[PinglunliebiaoViewController alloc] init];
        [self showViewController:pinglunliebiaoViewController sender:nil];
    }
}

#pragma mark - 选择规格
- (void)selectedTagsChanged: (VOTagList *)tagList
{
    NSLog(@"%ld", (unsigned long)tagList.selectedIndexSet.firstIndex);
}

#pragma mark - 分享
- (void )btn_fenxiangAction:(UIButton *)sender
{
    NSLog(@"点击分享");
}

#pragma mark - 收藏
- (void )btn_shoucangAction:(UIButton *)sender
{
    NSLog(@"点击收藏");
}

#pragma mark - 加入购物车
- (void )btn_jiaruGWCAction:(UIButton *)sender
{
    NSLog(@"加入购物车");
}

#pragma mark - 去结算
- (void )btn_qujiesuanAction:(UIButton *)sender
{
//    NSLog(@"去购物车结算");
    
    QugouwuchejiesuanViewController * qugouwuchejiesuanViewController = [[QugouwuchejiesuanViewController alloc] init];
    [self showViewController:qugouwuchejiesuanViewController sender:nil];
}

#pragma mark - web(图文混排)
- (void )p_webView
{
    self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 0)];
    NSString * path = @"http://www.baidu.com";
    NSURL * url = [NSURL URLWithString:path];
    [self.webView loadRequest:[NSURLRequest requestWithURL:url]];
    //
    [self webViewDidFinishLoad:self.webView];
    self.webView.backgroundColor = [UIColor groupTableViewBackgroundColor];
}

#pragma mark - 底部视图
- (void )p_bottomView
{
    UIView * view_bottom = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT - 50, SCREEN_WIDTH, 50)];
    view_bottom.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view_bottom];
    
    //
    UIImageView * image_fenxiang = [[UIImageView alloc] initWithFrame:CGRectMake(15, 8, 20, 20)];
    image_fenxiang.image = [UIImage imageNamed:@"fenxiang@2x.png"];
    [view_bottom addSubview:image_fenxiang];
    
    UILabel * name_fenxiang = [[UILabel alloc] initWithFrame:CGRectMake(10, CGRectGetMaxY(image_fenxiang.frame) + 5, 30, 10)];
    name_fenxiang.text = @"分享";
    name_fenxiang.font = [UIFont systemFontOfSize:11];
    name_fenxiang.textAlignment = NSTextAlignmentCenter;
    [view_bottom addSubview:name_fenxiang];
    
    UIButton * btn_fenxiang = [UIButton buttonWithType:(UIButtonTypeSystem)];
    btn_fenxiang.frame = CGRectMake(5, 3, 40, 44);
    [view_bottom addSubview:btn_fenxiang];
    [btn_fenxiang addTarget:self action:@selector(btn_fenxiangAction:) forControlEvents:(UIControlEventTouchUpInside)];
    
    UIView * view_line = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(image_fenxiang.frame) + 15, 5, 1, 40)];
    view_line.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [view_bottom addSubview:view_line];
    
    //
    UIImageView * image_shoucang = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(view_line.frame) + 15, 8, 20, 20)];
    image_shoucang.image = [UIImage imageNamed:@"shoucang@2x.png"];
    [view_bottom addSubview:image_shoucang];
    
    UILabel * name_shoucang = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(view_line.frame) + 10, CGRectGetMaxY(image_shoucang.frame) + 5, 30, 10)];
    name_shoucang.text = @"收藏";
    name_shoucang.font = [UIFont systemFontOfSize:11];
    name_shoucang.textAlignment = NSTextAlignmentCenter;
    [view_bottom addSubview:name_shoucang];
    
    UIButton * btn_shoucang = [UIButton buttonWithType:(UIButtonTypeSystem)];
    btn_shoucang.frame = CGRectMake(CGRectGetMaxX(view_line.frame) + 5, 3, 40, 44);
    [view_bottom addSubview:btn_shoucang];
    [btn_shoucang addTarget:self action:@selector(btn_shoucangAction:) forControlEvents:(UIControlEventTouchUpInside)];
    
    UIView * view_line1 = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(image_shoucang.frame) + 15, 5, 1, 40)];
    view_line1.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [view_bottom addSubview:view_line1];
    
    CGFloat length_x = (SCREEN_WIDTH - CGRectGetMaxX(view_line1.frame) - 30) / 2;
    
    //
    UIButton * btn_jiaruGWC = [UIButton buttonWithType:(UIButtonTypeSystem)];
    btn_jiaruGWC.frame = CGRectMake(CGRectGetMaxX(view_line1.frame) + 10, 7, length_x, 36);
    btn_jiaruGWC.backgroundColor = navi_bar_bg_color;
    btn_jiaruGWC.layer.cornerRadius = 5;
    [btn_jiaruGWC setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    [btn_jiaruGWC setTitle:@"加入购物车" forState:(UIControlStateNormal)];
    btn_jiaruGWC.titleLabel.font = [UIFont systemFontOfSize:13];
    [view_bottom addSubview:btn_jiaruGWC];
    [btn_jiaruGWC addTarget:self action:@selector(btn_jiaruGWCAction:) forControlEvents:(UIControlEventTouchUpInside)];
    
    //
    UIButton * btn_qujiesuan = [UIButton buttonWithType:(UIButtonTypeSystem)];
    btn_qujiesuan.frame = CGRectMake(CGRectGetMaxX(btn_jiaruGWC.frame) + 10, 7, length_x, 36);
    btn_qujiesuan.backgroundColor = [UIColor blackColor];
    btn_qujiesuan.layer.cornerRadius = 5;
    [btn_qujiesuan setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    [btn_qujiesuan setTitle:@"去购物车结算" forState:(UIControlStateNormal)];
    btn_qujiesuan.titleLabel.font = [UIFont systemFontOfSize:13];
    [view_bottom addSubview:btn_qujiesuan];
    [btn_qujiesuan addTarget:self action:@selector(btn_qujiesuanAction:) forControlEvents:(UIControlEventTouchUpInside)];
}

#pragma mark - 轮播图
- (void)p_lunbotu
{
    self.arr_lunboData = @[@"",@""].mutableCopy;
    
    self.lunbo_scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_WIDTH)];
    self.lunbo_scrollView.pagingEnabled = YES;
    self.lunbo_scrollView.showsHorizontalScrollIndicator = NO;
    self.lunbo_scrollView.delegate = self;
    self.lunbo_scrollView.userInteractionEnabled = YES;
    //
    self.lunbo_scrollView.contentSize = CGSizeMake(SCREEN_WIDTH * self.arr_lunboData.count + 2, 0);
    
    if(self.arr_lunboData.count == 0)
    {
        self.lunbo_scrollView.scrollEnabled = NO;
        
        self.image1 = [[UIImageView alloc] init];
        self.image1.frame = CGRectMake(SCREEN_WIDTH * 0 , 0 , SCREEN_WIDTH, self.lunbo_scrollView.frame.size.height);
        [self.image1 sd_setImageWithURL:[NSURL URLWithString:@""] placeholderImage:[UIImage imageNamed:@"chanpingPic@2x.png"]];
        [self.lunbo_scrollView addSubview:self.image1];
    }
    else
    {
        [self lunsdsd];
        
        self.lunbo_pageControl = [[UIPageControl alloc] init];
        
        if(SCREEN_WIDTH == 320)
        {
            self.lunbo_pageControl.frame = CGRectMake(0, self.lunbo_scrollView.frame.size.height - 20, SCREEN_WIDTH, 18);
        }
        else if(SCREEN_WIDTH == 375)
        {
            self.lunbo_pageControl.frame = CGRectMake(- 27.5, self.lunbo_scrollView.frame.size.height - 20, SCREEN_WIDTH, 18);
        }
        else
        {
            self.lunbo_pageControl.frame = CGRectMake(- 47, self.lunbo_scrollView.frame.size.height - 20, SCREEN_WIDTH, 18);
        }
        //    self.lunbo_pageControl.backgroundColor = [UIColor orangeColor];
        self.lunbo_pageControl.numberOfPages = self.arr_lunboData.count;
        self.lunbo_pageControl.currentPageIndicatorTintColor = navi_bar_bg_color;
        self.lunbo_pageControl.pageIndicatorTintColor = [UIColor colorWithRed:202/255.0 green:218/255.0 blue:233/255.0 alpha:1];
    }
    //手势
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(lunbotuAction:)];
    tapGesture.numberOfTapsRequired = 1; //点击次数
    tapGesture.numberOfTouchesRequired = 1; //点击手指数
    [self.lunbo_scrollView addGestureRecognizer:tapGesture];
}

#pragma mark - 轮播图的点击事件
- (void)lunbotuAction:(id)sender
{
    NSLog(@"%ld",(long)self.lunbo_pageControl.currentPage);
}

#pragma mark - 定时器的方法!
- (void)timerAction
{
    CGFloat x = self.lunbo_scrollView.contentOffset.x;
    int count = x / SCREEN_WIDTH;
    
    if(count < self.arr_lunboData.count)
    {
        count ++;
        [UIView animateWithDuration:0.7f animations:^{
            
            self.lunbo_scrollView.contentOffset = CGPointMake(count * SCREEN_WIDTH, 0);
            self.lunbo_pageControl.currentPage = count - 1;
            
        }];
    }
    else if(count == self.arr_lunboData.count)
    {
        count ++;
        
        [UIView animateWithDuration:0.7f animations:^{
            
            self.lunbo_scrollView.contentOffset = CGPointMake(count * SCREEN_WIDTH, 0);
            self.lunbo_pageControl.currentPage = 0;
            
        }];
    }
    else
    {
        count = 2;
        self.lunbo_scrollView.contentOffset = CGPointMake(1 * SCREEN_WIDTH, 0);
        [UIView animateWithDuration:0.7f animations:^{
            
            self.lunbo_scrollView.contentOffset = CGPointMake(count * SCREEN_WIDTH, 0);
            self.lunbo_pageControl.currentPage = count - 1;
        }];
    }
}
#pragma mark - scrollView的代理方法
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    CGFloat x = self.lunbo_scrollView.contentOffset.x;
    
    int count = x / SCREEN_WIDTH;
    
    if(count == self.arr_lunboData.count + 1)
    {
        self.lunbo_scrollView.contentOffset = CGPointMake(SCREEN_WIDTH, 0);
        self.lunbo_pageControl.currentPage = 0;
    }
    else if(count == 0)
    {
        self.lunbo_scrollView.contentOffset = CGPointMake(self.arr_lunboData.count * SCREEN_WIDTH, 0);
        self.lunbo_pageControl.currentPage = self.arr_lunboData.count - 1;
    }
    else
    {
        self.lunbo_pageControl.currentPage = count - 1;
    }
}

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    if([self.lunbo_scrollView isEqual:scrollView])
    {
        [self.lunbo_timer invalidate];
    }
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
    if ([scrollView isEqual:self.lunbo_scrollView]) {
        
        self.lunbo_timer = [NSTimer scheduledTimerWithTimeInterval:3.0f target:self selector:@selector(timerAction) userInfo:nil repeats:YES];
    }
}

//
- (void)lunsdsd
{
    self.lunbo_scrollView.contentSize = CGSizeMake(SCREEN_WIDTH * (self.arr_lunboData.count + 2), 0);
    
    self.lunbo_pageControl.numberOfPages = self.arr_lunboData.count;
    
    self.lunbo_scrollView.scrollEnabled = YES;
    
    for (int i = 1; i <= self.arr_lunboData.count; i++)
    {
        UIImageView * image = [[UIImageView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH * i, 0, SCREEN_WIDTH, self.lunbo_scrollView.frame.size.height)];
        
        [image sd_setImageWithURL:[NSURL URLWithString:@""] placeholderImage:[UIImage imageNamed:@"chanpingPic@2x.png"]];
        
        [self.lunbo_scrollView addSubview:image];
    }
    
    self.image1 = [[UIImageView alloc] init];
    self.image1.frame = CGRectMake(SCREEN_WIDTH * 0 , 0 , SCREEN_WIDTH, self.lunbo_scrollView.frame.size.height);
    [self.image1 sd_setImageWithURL:[NSURL URLWithString:@""] placeholderImage:[UIImage imageNamed:@"chanpingPic@2x.png"]];
    [self.lunbo_scrollView addSubview:self.image1];
    
    self.image2 = [[UIImageView alloc] init];
    self.image2.frame = CGRectMake(SCREEN_WIDTH * (self.arr_lunboData.count + 1), 0 , SCREEN_WIDTH, self.lunbo_scrollView.frame.size.height);
    [self.image2 sd_setImageWithURL:[NSURL URLWithString:@""] placeholderImage:[UIImage imageNamed:@"chanpingPic@2x.png"]];
    [self.lunbo_scrollView addSubview:self.image2];
    
    if(self.isplay == 0)
    {
        self.lunbo_scrollView.contentOffset = CGPointMake(SCREEN_WIDTH, 0);
        //轮播秒数
        self.lunbo_timer = [NSTimer scheduledTimerWithTimeInterval:3.0f target:self selector:@selector(timerAction) userInfo:nil repeats:YES];
        self.lunbo_pageControl.currentPage = 0;
        
        self.isplay = 1;
    }
    else
    {
        self.lunbo_scrollView.contentOffset = CGPointMake(SCREEN_WIDTH * (self.lunbo_pageControl.currentPage + 1), 0);
    }
}

#pragma mark - 懒加载
- (NSMutableArray *)arr_lunboData
{
    if(_arr_lunboData == nil)
    {
        self.arr_lunboData = [NSMutableArray array];
    }
    return _arr_lunboData;
}

- (NSMutableArray *)arr_listData
{
    if(_arr_listData == nil)
    {
        self.arr_listData = [NSMutableArray array];
    }
    return _arr_listData;
}

#pragma mark - web
-(void)webViewDidFinishLoad:(UIWebView *)webView
{    
    CGFloat webViewHeight= [[webView stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight"]floatValue];
    //    CGFloat webViewHeight= [[webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight"]floatValue];
    CGRect newFrame = webView.frame;
    newFrame.size.height = webViewHeight;
    webView.frame = newFrame;
}








@end
